package main

import (
	"fmt"
)

func longestCommonPrefix(strs []string) string {
	if len(strs) == 0 {
		return ""
	}
	//z := strs[0]
	prefix := strs[0]
	for _, str := range strs {
		for len(prefix) > 0 && len(str) > 0 && (len(prefix) > len(str) || str[:len(prefix)] != prefix) {
			prefix = prefix[:len(prefix)-1] // 减少前缀的长度
		}
		if len(prefix) == 0 {
			return ""
		}
	}
	return prefix
}

func main() {
	a := longestCommonPrefix([]string{"ab", "a", ""})
	fmt.Println(a)
	//b := "abcd"
	//fmt.Println(b[:4])

}

//"flower","flow","flight"
//"ab", "a"
